﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess.DataObject;

namespace DataAccess.BusinessObject
{
    public class BCategory_Post:Common.CDBase
    {
        /// <summary>
        /// Thêm chuyên mục cho bài viết
        /// </summary>
        /// <param name="IDCat"></param>
        /// <param name="IDPost"></param>
        /// <returns></returns>
        public bool Add(int IDCat, int IDPost)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDCat",SqlDbType.Int),
                                        new SqlParameter("@IDPost",SqlDbType.Int)};
            sqlParam[0].Value = IDCat;
            sqlParam[1].Value = IDPost;
            return RunProcedure("sp_tblCategory_Post_add", sqlParam);
        }
        public bool Delete(int IDPost)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDPost",SqlDbType.Int)};
            sqlParam[0].Value = IDPost;
            return RunProcedure("sp_tblCategory_Post_delete", sqlParam);
        }
        /// <summary>
        /// Đếm số bài viết trong category
        /// </summary>
        /// <param name="CatID"></param>
        /// <returns></returns>
        public int CountPost(int CatID)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@CatID",SqlDbType.Int)};
            sqlParam[0].Value = CatID;
            DataTable dtb = RunProcedureGet("sp_tblCategory_Post_countpost", sqlParam);
            return int.Parse(dtb.Rows[0]["Count"].ToString());
        }
        public IList<OCategory_Post> Get(int IDPost)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDPost",SqlDbType.Int)};
            sqlParam[0].Value = IDPost;
            return Common.Common.ConvertTo<OCategory_Post>(RunProcedureGet("sp_tblCategory_Post_get",sqlParam));
        }
    }
}
